<!--

    Copyright © 2016-2024 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="tb-threshold-settings-panel" [formGroup]="thresholdSettingsFormGroup">
  <div class="tb-threshold-settings-title">{{ panelTitle | translate }}</div>
  <div class="tb-threshold-settings-panel-content">
    <div *ngIf="!hideYAxis" class="tb-form-row space-between column-xs">
      <div translate>widgets.time-series-chart.axis.y-axis</div>
      <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
        <mat-select formControlName="yAxisId">
          <mat-option *ngFor="let yAxis of yAxisIds" [value]="yAxis">
            {{ yAxis }}
          </mat-option>
        </mat-select>
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between">
      <div translate>widget-config.units-short</div>
      <tb-unit-input
        formControlName="units">
      </tb-unit-input>
    </div>
    <div class="tb-form-row space-between">
      <div translate>widget-config.decimals-short</div>
      <mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
        <input matInput formControlName="decimals" type="number" min="0" max="15" step="1" placeholder="{{ 'widget-config.set' | translate }}">
      </mat-form-field>
    </div>
    <div class="tb-form-row space-between column-lt-md">
      <mat-slide-toggle class="mat-slide" formControlName="showLabel">
        {{ 'widgets.time-series-chart.threshold.label' | translate }}
      </mat-slide-toggle>
      <div fxLayout="row" fxFlex.lt-md fxLayoutAlign="start center" fxLayoutGap="8px">
        <mat-form-field class="medium-width" fxFlex.lt-md appearance="outline" subscriptSizing="dynamic">
          <mat-select formControlName="labelPosition">
            <mat-option *ngFor="let position of timeSeriesThresholdLabelPositions" [value]="position">
              {{ timeSeriesThresholdLabelPositionTranslations.get(position) | translate }}
            </mat-option>
          </mat-select>
        </mat-form-field>
        <tb-font-settings formControlName="labelFont"
                          clearButton
                          disabledLineHeight
                          forceSizeUnit="px"
                          [previewText]="labelPreviewFn">
        </tb-font-settings>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="labelColor">
        </tb-color-input>
      </div>
    </div>
    <div class="tb-form-row space-between">
      <mat-slide-toggle class="mat-slide" formControlName="enableLabelBackground">
        {{ 'widgets.time-series-chart.threshold.label-background' | translate }}
      </mat-slide-toggle>
      <tb-color-input asBoxInput
                      colorClearButton
                      formControlName="labelBackground">
      </tb-color-input>
    </div>
    <div class="tb-form-panel">
      <div class="tb-form-panel-title" translate>widgets.time-series-chart.threshold.line-appearance</div>
      <div class="tb-form-row space-between">
        <div translate>widgets.time-series-chart.threshold.line-color</div>
        <tb-color-input asBoxInput
                        colorClearButton
                        formControlName="lineColor">
        </tb-color-input>
      </div>
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.line-type</div>
        <mat-form-field class="medium-width" appearance="outline" subscriptSizing="dynamic">
          <mat-select formControlName="lineType">
            <mat-option *ngFor="let lineType of timeSeriesLineTypes" [value]="lineType">
              {{ timeSeriesLineTypeTranslations.get(lineType) | translate }}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </div>
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.line-width</div>
        <mat-form-field class="medium-width number" appearance="outline" subscriptSizing="dynamic">
          <input matInput type="number" formControlName="lineWidth" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}"/>
        </mat-form-field>
      </div>
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.threshold.start-symbol</div>
        <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
          <mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="startSymbol">
              <mat-option *ngFor="let shape of echartsShapes" [value]="shape">
                {{ echartsShapeTranslations.get(shape) | translate }}
              </mat-option>
            </mat-select>
          </mat-form-field>
          <div class="tb-small-label" translate>widgets.time-series-chart.threshold.symbol-size</div>
          <mat-form-field appearance="outline" class="number flex" subscriptSizing="dynamic">
            <input matInput formControlName="startSymbolSize"
                   type="number" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}">
          </mat-form-field>
        </div>
      </div>
      <div class="tb-form-row space-between column-xs">
        <div translate>widgets.time-series-chart.threshold.end-symbol</div>
        <div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
          <mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic">
            <mat-select formControlName="endSymbol">
              <mat-option *ngFor="let shape of echartsShapes" [value]="shape">
                {{ echartsShapeTranslations.get(shape) | translate }}
              </mat-option>
            </mat-select>
          </mat-form-field>
          <div class="tb-small-label" translate>widgets.time-series-chart.threshold.symbol-size</div>
          <mat-form-field appearance="outline" class="number flex" subscriptSizing="dynamic">
            <input matInput formControlName="endSymbolSize"
                   type="number" min="0" step="1" placeholder="{{ 'widget-config.set' | translate }}">
          </mat-form-field>
        </div>
      </div>
    </div>
  </div>
  <div class="tb-threshold-settings-panel-buttons">
    <button mat-button
            color="primary"
            type="button"
            (click)="cancel()">
      {{ 'action.cancel' | translate }}
    </button>
    <button mat-raised-button
            color="primary"
            type="button"
            (click)="applyThresholdSettings()"
            [disabled]="thresholdSettingsFormGroup.invalid || !thresholdSettingsFormGroup.dirty">
      {{ 'action.apply' | translate }}
    </button>
  </div>
</div>
